<?php
/**
 * (exporter)
 */
namespace App\Exporter\Delivery;

use App\Models\Basics\SysPlatAccount;
use App\Models\Basics\SysCountry;
use App\Models\Delivery\MDAItem;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class MDDetailExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '发货单明细.csv';

    protected $headings = ['订单号','原订单号','订单日期','发货账号','国家', '商家SKU','数量',
                           '运输SLA','同步状态','追踪号','运输方式','收件名','收件国家','联系电话','发货日期'];

    public function map($model) : array
    {
        return [
            $model->merchant_fulfillment_order_id,
            $model->order->r_order_no ?? '',
            $model->order->displayable_order_date ?? '',
            SysPlatAccount::getAccountById($model->account_id),
            SysCountry::getCountryById($model->country_id),
            $model->merchant_sku,
            $model->quantity,
            $model->order->delivery_sla ?? '',
            MDAItem::$_syncStatus[$model->sync_status],
            $model->tracking_no,
            $model->shipping_method,
            $model->order->address->address_name ?? '',
            $model->order->address->address_country_code ?? '',
            $model->order->address->address_phone_number ?? '',
            $model->created_at];
    }
}
